 	 cd "${data}"
	 use "dataset.dta", clear 
*FIGURE 3

******************* COHEN D ******************
 
 *NOTE: Create a folder in data folder and name it "cohend"
 	 cd "${data}"
	 use "dataset.dta", clear 
 *keep if samplelimit==1
 
 foreach var of varlist selfplacement redistribution regulation spending samesexmarriage immigration environment laworder euintegration {
	 keep country_year_ `var' voted samplelimit
	 bysort country_year_: egen mean_voter = mean(`var') if voted==1 
	 bysort country_year_: egen mean_nonvoter = mean(`var') if voted==0 
	 bysort country_year_: egen sd_ = sd(`var') 
     drop `var' voted 
	 duplicates drop 
	 collapse (mean) mean_voter mean_nonvoter sd_, by(country_year_) 
	 gen difference = abs(mean_voter - mean_nonvoter)
	 gen cohend = difference / sd_
	 cd "${data}/cohend"
	 save "`var'.dta", replace 
	 cd "${data}"
	 use "dataset.dta", clear 
}
  

cd "${data}/cohend"

use "selfplacement.dta", clear 
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/selfplacement.dta"
save "selfplacement_.dta", replace 

use "redistribution.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/redistribution.dta"

save "redistribution_.dta", replace  

use "regulation.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/regulation.dta"

save "regulation_.dta", replace  

use "spending.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/spending.dta"

save "spending_.dta", replace  


use "environment.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/environment.dta"

save "environment_.dta", replace  

use "immigration.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/immigration.dta"

save "immigration_.dta", replace  

use "samesexmarriage.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/samesexmarriage.dta"

save "samesexmarriage_.dta", replace  

use "laworder.dta", clear
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/laworder.dta"

save "laworder_.dta", replace  

use "euintegration.dta", clear  
gen sample = country_year_
merge 1:1 sample using "${data}/pvalues/euintegration.dta"

save "euintegration_.dta", replace  


 cd "${data}/cohend"


use "selfplacement_.dta", clear 
append using "redistribution_.dta" 
append using "regulation_.dta" 
append using "spending_.dta" 
append using "environment_.dta" 
append using "immigration_.dta" 
append using "samesexmarriage_.dta" 
append using "laworder_.dta" 
append using "euintegration_.dta"


*drop if cohend==. | p_voted==.


label define itemlabels 1"left-right" 2"redistribution" 3"regulation" 4"spending" 5"environment" 6"immigration" 7"same-sex marriage" 8"civil liberties" 9"EU integration"
 label values item itemlabels 
  label values item itemlabels 

gen significant = .
replace significant = 1 if p_voted<0.050
replace significant = 0 if p_voted>0.049

drop if _merge!=3 // because spending only in 2014. 

  dotplot cohend, over(item) center xlabel(, angle(90) labsize(small)) xtitle("") yscale(range(0(0.2)0.6)) ylabel(0(0.2)0.6) yline(0.2, lpattern(dash) lcolor(black)) mcolor(gs9%30) msize(small) jitter(2) ysize(6) xsize(8) yline(0.5) colorvar(significant) colorrule(%25) colordiscrete coloruseplegend colorlist(gs12%50 black%70)
  graph save "${figures}/Figure3.gph", replace 
  graph export "${figures}/Figure3.png", as(png) replace 

